package controller;

import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import common.model.Lukedate;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import service.DbRealmService;
import service.LukeService;
import util.DateUtil;

import java.io.File;
import java.util.Date;

@Path(value = "/admin/luke", viewPath = "/pages")
@RequiresAuthentication
public class LukeshijianController extends Controller {

    LukeService lukeService=new LukeService();

    public void index(){
        render("luke-shijian.html");
    }

    public void list(){
        int page=getInt("page");
        int size=getInt("limit");
        setAttr("datas",lukeService.getDatasByPage(page,size));
        setAttr("erro",0);
        renderJson();
    }

    public void record(){
        render("luke-list.html");
    }

    public void recordlist(){
        int page=getInt("page");
        int size=getInt("limit");
        setAttr("datas",lukeService.getRecordByPage(page,size));
        setAttr("erro",0);
        renderJson();
    }

    public void delrecord(){
        String id=get("id");
        lukeService.deleteRecordById(id);
        renderJson("erro",0);
    }

    public void upload(){
        File file=getFile().getFile();
        setAttr("msg",lukeService.importFromFile(file));
        setAttr("erro",0);
        renderJson();
    }

    public void edt(){
        Lukedate lukedate=lukeService.getDataById(get("id"));
        lukedate.setJieci(Integer.valueOf(get("jieci")));
        lukedate.setXingqi1(get("xingqi1"));
        lukedate.setXingqi2(get("xingqi2"));
        lukedate.setXingqi3(get("xingqi3"));
        lukedate.setXingqi4(get("xingqi4"));
        lukedate.setXingqi5(get("xingqi5"));
        lukeService.updateData(lukedate);
        setAttr("erro",0);
        renderJson();
    }

    public void exportdata(){
        String date=get("date");
        setAttr("erro",0);
        setAttr("file",lukeService.exportAllRecords(date));
        renderJson();
    }
}
